package com.qianclass.talklive.app.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.TextView;

import com.qianclass.talklive.R;
import com.qianclass.talklive.app.bean.ExpiredRoomsBean;

import java.util.List;

/**
 * Created by admin on 2016/12/29.
 * <p>
 * 更新时间 2016/12/29
 * 更新描述 ${TODO}
 */

public class ExpiredCourseAdapter extends BaseAdapter {
    private Context                mContext;
    private List<ExpiredRoomsBean> mExpiredList;
    private LayoutInflater         inflater;
    public ExpiredCourseAdapter(Context context, List<ExpiredRoomsBean>mExpiredList){
        this.mContext=context;
        this.mExpiredList=mExpiredList;
        inflater= LayoutInflater.from(context);
    }
    @Override
    public int getCount() {
        return mExpiredList !=null ?mExpiredList.size() : 0;
    }

    @Override
    public Object getItem(int position) {
        return mExpiredList !=null ?mExpiredList.get(position):0;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup viewGroup) {
        if (convertView == null) {

            //convertView = inflater.inflate(R.layout.xlistview_expiredcourse_item, null);
            convertView = inflater.inflate(R.layout.item_expired_course_content, null);
            //对于listview，注意添加这一行，即可在item上使用高度
        }

        TextView tv1 = (TextView) convertView.findViewById(R.id.tv_expired_course_name);
        TextView tv2 = (TextView) convertView.findViewById(R.id.tv_expired_course_time);
        TextView tv3 = (TextView) convertView.findViewById(R.id.tv_expired_course_teacher);

        ExpiredRoomsBean eclassCourseBean = mExpiredList.get(position);
        if (eclassCourseBean != null) {
            tv1.setText(eclassCourseBean.getRoomTitle());
            tv2.setText(eclassCourseBean.getStartDateTime());
            tv3.setText(eclassCourseBean.getTeacherName());
        } else {
            tv1.setText("");
            tv2.setText("");
            tv3.setText("");

        }
        Button but_enter_coures = (Button) convertView
                .findViewById(R.id.but_enter_expired_course);


        but_enter_coures.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //里边的代码主要是触发传值事件
                if(mOnTestClick!=null){
                    mOnTestClick.OnClick(position);
                }

            }
        });

        return convertView;
    }

    private OnTestClick mOnTestClick;
    public void setOnClick(OnTestClick onTestClick){
        mOnTestClick=onTestClick;
    }
    public interface OnTestClick{
        void OnClick(int position);
    }
}
